#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e4+10;
int a[N],b[N];

int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> b[i];
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    int i = 1,j = 1;
    for(;i <= n && j <= m;)
    {
        if(a[i] > b[j])
        {
            cout << b[j] << ' ';
            j++;
        }
        else if(a[i] < b[j])
        {
            cout << a[i] << " ";
            i++;
        }
        else
        {
            cout << a[i] << " ";
            i++;
            j++;
        }
    }
    while(i <= n)
    {
        cout << a[i++] << " ";
    }
    while(j <= m)
    {
        cout << b[j++] << " ";
    }
}
// 64 位输出请用 printf("%lld")